<?php
namespace Admin\Controller;
use Think\Controller;

class UserController extends Controller{
    public function login(){
        $this->display('Index/login');
    }
    public function logDo(){
        if($_POST){
            //判断验证码
            //            $verCode=$_POST['verCode'];
            //            if(!$this->checkVerify($verCode)) {
            //                $this->error('验证码错误！');
            //            }
            //用户登陆
            $model=M('Admin');
            $userName=$_POST['userName'];
            $userPass=md5(md5(trim($_POST['userPass'])));
    
            $adminInfo=$model->where("username='".$userName."'")->find();
            if($adminInfo){
                if($adminInfo['status']==1){
                        if($userPass==$adminInfo['password']){
                            session('adminId',$adminInfo['id']);
                            session('adminName',$adminInfo['username']);
                            $this->success('登陆成功！',U('Index/index'));
                        }else{
                            $this->error('密码错误！');
                        }
                }else{
                    $this->error('用户不存在或被禁用');
                }
            }else{
                $this->error('账号不存在！');
            }
        }
    }
}